﻿<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:threading="clr-namespace:System.Windows.Threading;assembly=WindowsBase"
    xmlns:v="clr-namespace:ShredTheLog.Views;assembly=ShredTheLog.Views"
    xmlns:vm="clr-namespace:ShredTheLog.ViewModels;assembly=ShredTheLog.ViewModels"
    xmlns:cnv="clr-namespace:ShredTheLog.Converters;assembly=ShredTheLog.Converters"
    xmlns:c="clr-namespace:ShredTheLog.Controls;assembly=ShredTheLog.Controls"
    xmlns:se="clr-namespace:ShredTheLog.ShaderEffectLibrary;assembly=ShredTheLog.ShaderEffectLibrary"
    >

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="FlashMisc2.xaml"/>
        <ResourceDictionary Source="FlashImages\MessageBubble.xaml"/>
        <ResourceDictionary Source="FlashImages\People.xaml"/>
        <ResourceDictionary Source="FlashImages\Search.xaml"/>
        <ResourceDictionary Source="FlashImages\Email.xaml"/>
        <ResourceDictionary Source="FlashImages\Sound.xaml"/>
        <ResourceDictionary Source="FlashImages\User.xaml"/>
        <ResourceDictionary Source="FlashImages\Star.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="HomePageUserList" TargetType="{x:Type ItemsControl}">
        <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
        <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="ItemTemplate">
            <Setter.Value>
                <DataTemplate>
                    <WrapPanel Margin="4, 0, 4, 0">
                        <ContentPresenter Content="{Binding Gender}"/>
                        <TextBlock Margin="2, 0, 2, 0">
                            <Hyperlink Command="{Binding Converter={x:Static cnv:ShowProfileCommandConverter.Default}}" CommandParameter="{Binding}" Focusable="False">
                                <TextBlock Text="{Binding Path=Name}"/>
                            </Hyperlink>
                        </TextBlock>
                        <TextBlock Text="{Binding Path=Age, StringFormat=({0:d})}" Foreground="#881111" Margin="2, 0, 2, 0"/>
                        <TextBlock Text="{Binding Path=Country, Converter={x:Static cnv:CountryConverter.Default}}" Foreground="#115511" Margin="2, 0, 2, 0"/>
                    </WrapPanel>
                </DataTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel/>
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ItemsControl}">
                    <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                        <ScrollViewer CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                            <ItemsPresenter/>
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <DataTemplate DataType="{x:Type vm:HomePageViewModel}">
        <DockPanel x:Name="panel" Width="610">
            <Panel.Resources>

                <c:Timer x:Key="timer" Interval="0:1:0" FireOnStart="True" IsEnabled="{Binding ElementName=panel, Path=IsVisible, Mode=OneWay}" Command="{Binding UpdateUserListsCommand}"/>

                <Style x:Key="HomePageButton" TargetType="{x:Type Button}">
                    <Setter Property="Height" Value="63"/>
                    <Setter Property="Cursor" Value="{x:Static Cursors.Hand}"/>
                    <Setter Property="Background" Value="Transparent"/>
                    <Setter Property="BorderBrush" Value="Transparent"/>
                    <Setter Property="BorderThickness" Value="1"/>
                    <Setter Property="Focusable" Value="false"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type Button}">
                                <Grid>
                                    <Border x:Name="border" CornerRadius="3" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" Padding="2" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                                        <Grid x:Name="grid">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                            </Grid.ColumnDefinitions>
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto"/>
                                                <RowDefinition Height="*"/>
                                            </Grid.RowDefinitions>
                                            <Image x:Name="image" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Source="{Binding RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, Path=Content[2]}" Stretch="Uniform" VerticalAlignment="Stretch" Width="{Binding ElementName=grid, Path=ActualHeight, Mode=OneWay}" Margin="0, 0, 5, 0"/>
                                            <AccessText Grid.Column="1" Grid.Row="0" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, Path=Content[0]}" Style="{StaticResource AccessHeaderStyle}"/>
                                            <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, Path=Content[1]}" TextWrapping="Wrap" VerticalAlignment="Stretch"/>
                                        </Grid>
                                    </Border>

                                    <Rectangle x:Name="DisabledVisualElement" Fill="White" IsHitTestVisible="False" Opacity="0.5" Visibility="Collapsed"/>
                                </Grid>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter TargetName="border" Property="BorderBrush" Value="#888888"/>
                                        <Setter TargetName="border" Property="Background" Value="#EAEFFF"/>
                                    </Trigger>

                                    <Trigger Property="IsEnabled" Value="false">
                                        <Setter Property="Visibility" TargetName="DisabledVisualElement" Value="Visible"/>
                                        <Setter TargetName="border" Property="Effect">
                                            <Setter.Value>
                                                <se:MonochromeEffect FilterColor="#FAF0E6"/>
                                            </Setter.Value>
                                        </Setter>
                                    </Trigger>
                                </ControlTemplate.Triggers>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>

            </Panel.Resources>

            <Grid DockPanel.Dock="Top" Margin="5">
                <Border Style="{StaticResource ShadowedBorderStyle}"/>

                <Grid Margin="10, 0, 10, 8">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="{c:LocalizedString s_YourLanguageExchangeNetwork}" Foreground="{StaticResource HeaderTextBrush}" FontSize="28" TextAlignment="Center" Margin="0, 0, 0, 8"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{c:LocalizedString s_SharedTalkIs}" TextWrapping="Wrap" TextAlignment="Center" Margin="0, 0, 0, 8"/>

                    <Button Grid.Row="2" Grid.Column="0" Command="{Binding RegisterCommand}" Background="{StaticResource GrayBackgroundBrush}" BorderBrush="#DADADA" BorderThickness="1" Style="{StaticResource HomePageButton}" Margin="5" Effect="{StaticResource LargeShadow}">
                        <x:Array Type="{x:Type sys:Object}">
                            <c:LocalizedStringExtension Key="s_Flash_Register"/>
                            <c:LocalizedStringExtension Key="s_RegisterDescription"/>
                            <StaticResourceExtension ResourceKey="PeopleIcon"/>
                        </x:Array>
                    </Button>

                    <Button Grid.Row="2" Grid.Column="1" Command="{Binding DiscoverSharedTalkCommand}" Style="{StaticResource HomePageButton}" Margin="5">
                        <x:Array Type="{x:Type sys:Object}">
                            <c:LocalizedStringExtension Key="s_DiscoverSharedTalk"/>
                            <c:LocalizedStringExtension Key="s_DiscoverSharedTalkDescription"/>
                            <StaticResourceExtension ResourceKey="StarIcon"/>
                        </x:Array>
                    </Button>
                </Grid>
            </Grid>

            <Grid Margin="20, 10, 20, 0">
                <Panel.Resources>
                    <Style x:Key="UserCountTextBlock" TargetType="{x:Type TextBlock}">
                        <Setter Property="Background" Value="{StaticResource GrayBackgroundBrush}"/>
                        <Setter Property="Padding" Value="8, 3, 8, 3"/>
                    </Style>
                </Panel.Resources>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="10"/>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <Button Grid.Row="0" Grid.Column="0" Command="{Binding GoToUserSearchCommand}" Style="{StaticResource HomePageButton}">
                    <x:Array Type="{x:Type sys:Object}">
                        <c:LocalizedStringExtension Key="s_UserSearch"/>
                        <c:LocalizedStringExtension Key="s_UserSearchDescription"/>
                        <StaticResourceExtension ResourceKey="SearchIcon"/>
                    </x:Array>
                </Button>

                <Button Grid.Row="0" Grid.Column="1" Command="{Binding GoToMailboxCommand}" Style="{StaticResource HomePageButton}">
                    <x:Array Type="{x:Type sys:Object}">
                        <c:LocalizedStringExtension Key="s_Mailbox"/>
                        <c:LocalizedStringExtension Key="s_MailboxDescription"/>
                        <StaticResourceExtension ResourceKey="EmailIcon"/>
                    </x:Array>
                </Button>

                <Button Grid.Row="1" Grid.Column="0" Command="{Binding GoToVoiceChatCommand}" Style="{StaticResource HomePageButton}">
                    <x:Array Type="{x:Type sys:Object}">
                        <c:LocalizedStringExtension Key="s_VoiceChat"/>
                        <c:LocalizedStringExtension Key="s_VoiceChatDescription"/>
                        <StaticResourceExtension ResourceKey="SoundIcon"/>
                    </x:Array>
                </Button>

                <Button Grid.Row="1" Grid.Column="1" Command="{Binding EditProfileCommand}" Style="{StaticResource HomePageButton}">
                    <x:Array Type="{x:Type sys:Object}">
                        <c:LocalizedStringExtension Key="s_EditProfile"/>
                        <c:LocalizedStringExtension Key="s_EditProfileDescription"/>
                        <StaticResourceExtension ResourceKey="UserIcon"/>
                    </x:Array>
                </Button>

                <Button Grid.Row="2" Grid.Column="0" Command="{Binding GoToTextChatCommand}" Style="{StaticResource HomePageButton}">
                    <x:Array Type="{x:Type sys:Object}">
                        <c:LocalizedStringExtension Key="s_Menu_TextChat"/>
                        <c:LocalizedStringExtension Key="s_TextChatDescription"/>
                        <StaticResourceExtension ResourceKey="MessageBubbleIcon"/>
                    </x:Array>
                </Button>

                <Button Grid.Row="2" Grid.Column="1" Command="{Binding GoToContactListCommand}" Style="{StaticResource HomePageButton}">
                    <x:Array Type="{x:Type sys:Object}">
                        <c:LocalizedStringExtension Key="s_Menu_ContactList"/>
                        <c:LocalizedStringExtension Key="s_ContactListDescription"/>
                        <StaticResourceExtension ResourceKey="PeopleIcon"/>
                    </x:Array>
                </Button>

                <GroupBox Grid.Row="4" Grid.Column="0" Header="{c:LocalizedString s_UsersInTheVoiceChat}" Style="{StaticResource BlueGroupBoxStyle}">
                    <DockPanel>
                        <TextBlock DockPanel.Dock="Top" Text="{Binding Path=VoiceChatUsers.Count, StringFormat={c:LocalizedString s_ThereAreXPeople}}" Style="{StaticResource UserCountTextBlock}"/>
                        <TextBlock DockPanel.Dock="Bottom" Background="{StaticResource GrayBackgroundBrush}" Padding="8, 3, 8, 3">
                            <TextBlock Text="♦"/>
                            <Hyperlink Command="{Binding GoToVoiceChatCommand}"><TextBlock Text="{c:LocalizedString s_ChatNow}"/></Hyperlink>
                        </TextBlock>
                        <ItemsControl ItemsSource="{Binding VoiceChatUsers}" Style="{StaticResource HomePageUserList}"/>
                    </DockPanel>
                </GroupBox>

                <GroupBox Grid.Row="4" Grid.Column="1" Header="{c:LocalizedString s_UsersInTheTextChat}" Style="{StaticResource BlueGroupBoxStyle}">
                    <DockPanel>
                        <TextBlock DockPanel.Dock="Top" Text="{Binding Path=TextChatUsers.Count, StringFormat={c:LocalizedString s_ThereAreXPeople}}" Style="{StaticResource UserCountTextBlock}"/>
                        <TextBlock DockPanel.Dock="Bottom" Background="{StaticResource GrayBackgroundBrush}" Padding="8, 3, 8, 3">
                            <TextBlock Text="♦"/>
                            <Hyperlink Command="{Binding GoToTextChatCommand}"><TextBlock Text="{c:LocalizedString s_ChatNow}"/></Hyperlink>
                        </TextBlock>
                        <ItemsControl ItemsSource="{Binding TextChatUsers}" Style="{StaticResource HomePageUserList}"/>
                    </DockPanel>
                </GroupBox>

                <GroupBox Grid.Row="5" Grid.Column="0" Header="{c:LocalizedString s_NewUsers}" Style="{StaticResource BlueGroupBoxStyle}">
                    <ItemsControl ItemsSource="{Binding Last15Users}" Style="{StaticResource HomePageUserList}"/>
                </GroupBox>
            </Grid>

        </DockPanel>
    </DataTemplate>
</ResourceDictionary>